home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / SoundSprocketTest / TS3Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  6.1 KB  |  314 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        TS3Events.c
  3.  *
  4.  *    Contents:    Handles the events.
  5.  *
  6.  *    Copyright © 1996 Apple Computer, Inc.
  7.  */
  8.  
  9. #include <assert.h>
  10.  
  11. #include <AppleEvents.h>
  12. #include <Events.h>
  13. #include <ToolUtils.h>
  14. #include <Types.h>
  15. #include <Windows.h>
  16.  
  17. #include "TS3Events.h"
  18. #include "TS3Main.h"
  19. #include "TS3Menu.h"
  20. #include "TS3Window.h"
  21.  
  22.  
  23. static void Events_MouseDown(
  24.     const EventRecord*        inEvent);
  25.  
  26. static void Events_KeyDown(
  27.     const EventRecord*        inEvent);
  28.  
  29. static void Events_AutoKey(
  30.     const EventRecord*        inEvent);
  31.  
  32. static void Events_Update(
  33.     const EventRecord*        inEvent);
  34.  
  35. static void Events_Activate(
  36.     const EventRecord*        inEvent);
  37.  
  38. static void Events_OS(
  39.     const EventRecord*        inEvent);
  40.  
  41. static void Events_HighLevel(
  42.     const EventRecord*        inEvent);
  43.  
  44.  
  45. /* =============================================================================
  46.  *        Events_Init (external)
  47.  *
  48.  *    Initializes the events stuff.
  49.  * ========================================================================== */
  50. void Events_Init(
  51.     void)
  52. {
  53.     FlushEvents(everyEvent, 0);
  54. }
  55.  
  56.  
  57. /* =============================================================================
  58.  *        Events_Exit (external)
  59.  *
  60.  *    Prepares for exit.
  61.  * ========================================================================== */
  62. void Events_Exit(
  63.     void)
  64. {
  65. }
  66.  
  67.  
  68. /* =============================================================================
  69.  *        Events_Process (external)
  70.  *
  71.  *    Processes any pending events.
  72.  * ========================================================================== */
  73. void Events_Process(
  74.     void)
  75. {
  76.     UInt32                    sleep;
  77.     EventRecord                ev;
  78.     Boolean                    consumed;
  79.     
  80.     Window_GetSleep(FrontWindow(), &sleep);
  81.     
  82.     while (WaitNextEvent(everyEvent, &ev, sleep, NULL))
  83.     {
  84.         Window_ConsumeEvent(FrontWindow(), &ev, &consumed);
  85.         
  86.         if (!consumed)
  87.         {
  88.             switch (ev.what)
  89.             {
  90.                 case mouseDown:
  91.                     Events_MouseDown(&ev);
  92.                 break;
  93.                 
  94.                 case keyDown:
  95.                     Events_KeyDown(&ev);
  96.                 break;
  97.                 
  98.                 case autoKey:
  99.                     Events_AutoKey(&ev);
  100.                 break;
  101.                 
  102.                 case updateEvt:
  103.                     Events_Update(&ev);
  104.                 break;
  105.                 
  106.                 case activateEvt:
  107.                     Events_Activate(&ev);
  108.                 break;
  109.                 
  110.                 case osEvt:
  111.                     Events_OS(&ev);
  112.                 break;
  113.                 
  114.                 case kHighLevelEvent:
  115.                     Events_HighLevel(&ev);
  116.                 break;
  117.             }
  118.         }
  119.     }
  120.     
  121.     // Pass on a NULL event when WaitNextEvent returns false to keep dialog caret blinking
  122.     ev.what = nullEvent;
  123.     Window_ConsumeEvent(FrontWindow(), &ev, &consumed);
  124. }
  125.  
  126.  
  127. /* =============================================================================
  128.  *        Events_MouseDown (internal)
  129.  *
  130.  *    Processes a mouse-down event.
  131.  * ========================================================================== */
  132. void Events_MouseDown(
  133.     const EventRecord*        inEvent)
  134. {
  135.     short                     part;
  136.     WindowPtr                wind;
  137.     long                    menu;
  138.     
  139.     assert(inEvent != NULL);
  140.     
  141.     part = FindWindow(inEvent->where, &wind);
  142.     
  143.     switch (part)
  144.     {
  145.         case inMenuBar:
  146.             menu = MenuSelect(inEvent->where);
  147.             Menu_Select(HiWord(menu), LoWord(menu));
  148.         break;
  149.             
  150.         case inSysWindow:
  151.             SystemClick(inEvent, wind);
  152.         break;
  153.             
  154.         case inDrag:
  155.             DragWindow(wind, inEvent->where, &qd.screenBits.bounds);
  156.         break;
  157.             
  158.         case inGoAway:
  159.             Main_LastRoundup();
  160.         break;
  161.                 
  162.         case inContent:
  163.             if (wind == FrontWindow())
  164.             {
  165.                 Window_MouseDown(wind, inEvent->where);
  166.             }
  167.             else
  168.             {
  169.                 SelectWindow(wind);
  170.             }
  171.         break;
  172.             
  173.         case inGrow:
  174.             // nothing yet...
  175.         break;
  176.     }
  177. }
  178.  
  179.  
  180. /* =============================================================================
  181.  *        Events_KeyDown (internal)
  182.  *
  183.  *    Processes a key-down event.
  184.  * ========================================================================== */
  185. void Events_KeyDown(
  186.     const EventRecord*        inEvent)
  187. {
  188.     unsigned long            ch;
  189.     unsigned long            cap;
  190.     long                    menu;
  191.     
  192.     assert(inEvent != NULL);
  193.     
  194.     ch = inEvent->message & charCodeMask;
  195.     cap = (inEvent->message & keyCodeMask) >> 8;
  196.     
  197.     if ((inEvent->modifiers & cmdKey) == 0)
  198.     {
  199.         Window_KeyDown(FrontWindow(), ch, cap, inEvent->modifiers, false);
  200.     }
  201.     else
  202.     {
  203.         menu = MenuKey(ch);
  204.         Menu_Select(HiWord(menu), LoWord(menu));
  205.     }
  206. }
  207.  
  208.  
  209. /* =============================================================================
  210.  *        Events_AutoKey (internal)
  211.  *
  212.  *    Processes an auto-key event.
  213.  * ========================================================================== */
  214. void Events_AutoKey(
  215.     const EventRecord*        inEvent)
  216. {
  217.     unsigned long            ch;
  218.     unsigned long            cap;
  219.     
  220.     assert(inEvent != NULL);
  221.     
  222.     ch = inEvent->message & charCodeMask;
  223.     cap = (inEvent->message & keyCodeMask) >> 8;
  224.     
  225.     if ((inEvent->modifiers & cmdKey) == 0)
  226.     {
  227.         Window_KeyDown(FrontWindow(), ch, cap, inEvent->modifiers, true);
  228.     }
  229. }
  230.  
  231.  
  232. /* =============================================================================
  233.  *        Events_Update (internal)
  234.  *
  235.  *    Processes an update event.
  236.  * ========================================================================== */
  237. void Events_Update(
  238.     const EventRecord*        inEvent)
  239. {
  240.     WindowPtr                wind;
  241.     
  242.     assert(inEvent != NULL);
  243.     
  244.     wind = (WindowPtr) inEvent->message;
  245.     
  246.     if (Window_IsMine(wind))
  247.     {
  248.         SetPort(wind);
  249.         BeginUpdate(wind);
  250.         Window_Update(wind);
  251.         EndUpdate(wind);
  252.     }
  253. }
  254.  
  255.  
  256. /* =============================================================================
  257.  *        Events_Activate (internal)
  258.  *
  259.  *    Processes an activate event.
  260.  * ========================================================================== */
  261. void Events_Activate(
  262.     const EventRecord*        inEvent)
  263. {
  264.     WindowPtr                wind;
  265.     
  266.     assert(inEvent != NULL);
  267.     
  268.     wind = (WindowPtr) inEvent->message;
  269.     
  270.     if (inEvent->modifiers & activeFlag)
  271.     {
  272.         Window_Activate(wind);
  273.     }
  274.     else
  275.     {
  276.         Window_Deactivate(wind);
  277.     }
  278. }
  279.  
  280.  
  281. /* =============================================================================
  282.  *        Events_OS (internal)
  283.  *
  284.  *    Processes an OS event.
  285.  * ========================================================================== */
  286. void Events_OS(
  287.     const EventRecord*        inEvent)
  288. {
  289.     assert(inEvent != NULL);
  290.     
  291.     if ((inEvent->message >> 24) & 0xFF == suspendResumeMessage)
  292.     {
  293.         // nothing yet...
  294.     }
  295. }
  296.  
  297.  
  298. /* =============================================================================
  299.  *        Events_HighLevel (internal)
  300.  *
  301.  *    Processes a high-level event.
  302.  * ========================================================================== */
  303. void Events_HighLevel(
  304.     const EventRecord*        inEvent)
  305. {
  306.     assert(inEvent != NULL);
  307.     
  308.     AEProcessAppleEvent(inEvent);
  309. }
  310.  
  311.  
  312.  
  313.  
  314.